﻿@model ShivamEMR.Model.Domain.PatientDomain.Patient
 
   
<table id="patientContacts">
    <tr>
        <th></th>
        <th>
            Title
        </th>
        <th>
            Value
        </th>
        <th>
            Notes
        </th>
        <th>
            ContactType
        </th>
        
    </tr>

@foreach (var item in Model.Contacts) {
    <tr>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
        <td>
			@item.Title
        </td>
        <td>
			@item.Value
        </td>
        <td>
			@item.Notes
        </td>
        <td>
			@Html.DisplayTextFor(_ => item.ContactType).ToString()
        </td>
        
    </tr>
}

</table>

     @Html.ActionLink("Add Contact..", "NewContact", "Patient", new { @class = "editLink" })          

<div id="updateDialog" title="Add Contact"></div>
<script type="text/javascript">

    var linkObj;
    $(function () {
        $(".editLink").button();

        $('#updateDialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true,
            buttons: {
                "Add": function () {
                    $("#patientContacts").html(''); //make sure there is nothing on the message before we continue                         
                    $("#updateCarForm").submit();
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".editLink").click(function () {
            //change the title of the dialog
            linkObj = $(this);
            var dialogDiv = $('#updateDialog');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //validation
                var $form = $("#updateCarForm");
                // Unbind existing validation
                $form.unbind();
                $form.data("validator", null);
                // Check document for changes
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });

    });


    function AddressSuccess(data) {
        if (data.Success == true) {
            $('#updateDialog').dialog('close');
        }
        else {
            $("#update-message").html(data.ErrorMessage);
            $("#update-message").show();
        }
    }


//    function updateSuccess() {
//        if ($("#patientContacts").html() == "True") {
//            $('#updateDialog').dialog('close');
//            //twitter type notification
//         //   $('#commonMessage').html("Update Complete");
//           // $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
//        }
//        else {
//            $("#patientContacts").show();
//        }
//    }


    //    function updateSuccess(data) {
    //        if (data.Success == true)
    //         {             
    //            $('#updateDialog').dialog('close');
    //            //twitter type notification
    //           //$('#commonMessage').html("Update Complete");
    //          //  $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
    //        }
    //        else {
    //            $("#update-message").html(data.ErrorMessage);
    //            $("#update-message").show();
    //        }
    //    }

 
    
</script>

